package spr;

import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.snapshot.RobotState;
import spr.test.RobotTestBed;
import static org.junit.Assert.assertTrue;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that after RastaBot
 * collides with another robot it returns a perpendicular heading in order to move along the walls
 * again.
 * 
 * @author Shaun Ramento
 */
public class TestRobotCollision extends RobotTestBed {
  Boolean collision = false;

  /**
   * Specifies that RamFire and RastaBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Walls,spr.RastaBot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Test to make sure after collision the robot returns a perpendicular heading.
   * 
   * @param event TurnEndedEvent
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // gets a snapshot of robot for each turn
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    RobotState currentState = robot.getState();
    double bodyHeading = robot.getBodyHeading();
    double robotHeadingDegrees = Math.toDegrees(bodyHeading);
    // Reveals if robot collides with another robot
    if ((currentState.isHitRobot()) && (((robotHeadingDegrees == 0) || 
        (robotHeadingDegrees == 90) || (robotHeadingDegrees == 180)
          || (robotHeadingDegrees == 360)))) {
        // Checks to make sure after collision it will return a perpendicular heading to any sd eof
        // the walls.
        System.out.println(currentState + ", " + robotHeadingDegrees);
        collision = true;
      
    }
  }

  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Robot collided with another robot.", collision);

  }
}